package org.vacoor.ticket.handler.impl;

import java.io.UnsupportedEncodingException;

import org.vacoor.ticket.Constant;
import org.vacoor.ticket.handler.ResultHandler;


public class LoginResultHandler implements ResultHandler<Integer>{
	public static final int OK_SUCCESS = 0;
	public static final int ERR_NAME_PASSWD = 1;
	public static final int ERR_AUTHCODE = 2;
	public static final int ERR_MAINTENANCE = 4;
	public static final int ERR_ILLEGAL_REQ = 8;
	public static final int ERR_UNKNOW = 16;

	@Override
	public Integer handler(byte[] result) {
		String content;
		try {
			content = new String(result,Constant.ENCODING);
		} catch (UnsupportedEncodingException e1) {
			// TODO Auto-generated catch block
			e1.printStackTrace();
			content = new String(result);
		}
		if (content.contains("欢迎")) {
			return OK_SUCCESS;
		} else if (content.contains("登录名不存在")
				|| content.contains("密码输入错误")) {
			return ERR_NAME_PASSWD;
		} else if (content.contains("请输入正确的验证码")) {
			return ERR_AUTHCODE;
		} else if (content.contains("系统维护")) {
			return ERR_MAINTENANCE;
		} else if (content.contains("拒绝访问")) {
			return ERR_ILLEGAL_REQ;
		} else {
			System.out.println("登录响应" + content);
			return ERR_UNKNOW;
		}
	}
}
